package com.leyou.cart.config;

import com.leyou.auth.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * @Author: Rose
 * @Date: 2021/4/10 16:05
 * @description ${description}
 * @version: 1.0.0
 */
@Data
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties {


    /**
     * 公钥
     */
    private String pubkeyPath;

    /**
     * tokenName
     */
    private String cookieName;

    /**
     * 过期时间
     */
    private int expire;

    private PublicKey pubKey;


    // 类一旦加载, 就应该读取公钥和私钥
    // 加载时机: 对象一旦实例化后,就应该读取公钥和私钥
    // 构造函数初始化完毕之后,调用此方法
    @PostConstruct
    public void init() throws Exception {
        // 读取公钥和私钥
        this.pubKey = RsaUtils.getPublicKey(pubkeyPath);
    }
}
